<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/12/21
 * Time: 10:19
 */

namespace HiCommon\Model;

use HiCommon\MongodbModel\MongoLoginShopUserLog;

class ShopUser extends Base
{
    
    protected $table = 'shop_user';
    
    protected $guarded = [];
    
    //public $timestamps = false;
    
    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];


    /**
     * 关联门店表
     *
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function shop_base(){
//        $arr_select = ['id','cate','name','company_name','logo','phone','name_boss','province','id','id','id','id','id','id','id','id'];
        return $this->belongsTo(Shop::class,'shop_id');
    }

    /**
     * 关联商户后台用户角色表
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function shop_role_user(){
        return $this->hasOne(EntrustRoleUser::class,'user_id')->where('model','shop')->select(['model','user_id','role_id']);
    }

    /**
     * 关联商户后台用户角色表
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function user_role(){
        return $this->hasOne(EntrustRoleUser::class,'user_id')->with('role')->where('model','shop')->select(['model','user_id','role_id']);
    }

    /**
     * 获取图片可用链接
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getImgUrlAttribute($value)
    {
        $arr_data = [
          'src'=>$value,
          'full_src'=>oss_full_url($value),
        ];
        return $arr_data;
    }

    /**
     * 获取头像可用链接
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getAvatarAttribute($value)
    {
        $arr_data = [
          'src'=>$value,
          'full_src'=>oss_full_url($value),
        ];
        return $arr_data;
    }
        
    /**
     * 扩展信息
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getExtendAttribute()
    {
        $arr_data = $this->arr_state_display_name();
        $arr_data['created_at'] = ymd_friendly_date($this->created_at);
        $arr_data['api'] = $this->table_field_api();

        return $arr_data;
    }


    /**
     * state 状态值数组
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function state_arr()
    {

        //状态：1启用 2禁用
        $arr_state = [
          ['id' => 1, 'name' => '启用'],
          ['id' => 2, 'name' => '禁用'],
        ];

        $arr_data = [
          'state'        => $arr_state,
        ];
        return $arr_data;
    }

//    /**
//     * 获取state值和注释的集合
//     *
//     * @return array
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function arr_state_name()
//    {
//        return $this->hi_arr_state_name($this->state_arr());
//    }

    /**
     * 获取state值对应的含义
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function arr_state_display_name()
    {
        return $this->hi_arr_state_display_name($this->state_arr());
    }



    
  
}